package com.szr.leex;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import lombok.extern.slf4j.Slf4j;

/**
 * 项目启动类
 * Created by WangChen on 2018/8/23 16:32.
 */
// 参考
// https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-using-springbootapplication-annotation.html
// https://qbgbook.gitbooks.io/spring-boot-reference-guide-zh/III.%20Using%20Spring%20Boot/18.%20Using%20the%20@SpringBootApplication%20annotation.html
// https://springbootdev.com/2017/11/13/what-are-the-uses-of-entityscan-and-enablejparepositories-annotations/
// same as @Configuration @EnableAutoConfiguration @ComponentScan
// @EnableAutoConfiguration: enable Spring Boot’s auto-configuration mechanism
//      The @EnableAutoConfiguration will scan the main package and its sub packages
//      when executing the spring boot auto configuration feature for class path dependencies.
//      If any class or package that is outside from the main application package
//      and it is required for completing auto configuration for some dependency,
//      then should be declared in the main configuration class properly (with related annotation).
// @ComponentScan: enable @Component scan on the package where the application is located (see the best practices)
// @Configuration: allow to register extra beans in the context or import additional configuration classes
// scanBasePackages默认为本包及其子目录，这里不再配置(scanBasePackages = "com.szr")
@SpringBootApplication/*(scanBasePackages = "com.szr")*/
//@EnableJpaRepositories(repositoryFactoryBeanClass = GenericJpaRepositoryFactoryBean.class)
// This will enable the JPA repositories that contains in the given package(s).
// For instance, Enabling auto configuration support for Spring Data JPA required to know the path of the JPA the repositories.
// By default, it will scan only the main application package and its sub packages for detecting the JPA repositories.
// Therefore, if the repository classes are not placed under the main application package or its sub package,
// then the relevant repository package(s) should be declared in the main application configuration class with @EnableJpaRepositories annotation.
// Then this will enable the JPA repositories contains in the given/declared package(s).
@EnableJpaRepositories
// If the entity classes are not placed in the main application package or its sub package(s),
// then it is required to declare the package(s) in the main configuration class with @EntityScan annotation.
// This will tells spring boot to where to scan for detecting the entities for the application.
// Basically @EnableAutoConfiguration will scan the given package(s) for detecting the entities.
// scanBasePackages默认为本包及其子目录，这里不再配置(scanBasePackages = "com.szr")
@EntityScan/*(basePackages = "com.szr")*/
@Slf4j

//@EnableTransactionManagement

public class Application {

    public static void main(String [] args){
    	ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
//    	DebtorInfoDao debtorInfoDao = context.getBean(DebtorInfoDao.class);
//    	Pageable pageable = new PageRequest(0,10);
//        Page page = debtorInfoDao.findDtoPage("dashu",pageable);
//        log.info(JSON.toJSONString(page, true));
    }

    @Bean
    public Object testBean(PlatformTransactionManager platformTransactionManager) {
        System.out.println(">>>>>>>>>>" + platformTransactionManager.getClass().getName());
        return new Object();
    }

}
